﻿<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<script runat="server">
    protected string Notice = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            string ys=this.Request.QueryString["y"];
            string ms = this.Request.QueryString["m"];
            int y=0,m=0;
            if (ys != null && ms != null)
            {
                if(int.TryParse(ys,out y) && int.TryParse(ms,out m))
                {
                    this.NianDu.Enabled = false;
                    this.YueFen.Enabled = false;
                }
            }

            if (y == 0)
            {
                y = DateTime.Today.Year;
            }
            if (this.NianDu.Items.FindByText(y.ToString()) == null)
            {
                ListItem li = new ListItem(y.ToString());
                this.NianDu.Items.Add(li);
            }
            this.NianDu.Text = y.ToString();
            this.YueFen.Text = m.ToString();
            if (!this.NianDu.Enabled)
            {
                SqlDataSource1.Select(DataSourceSelectArguments.Empty);
            }
        }
    }

    protected void SqlDataSource1_Selected(object sender, SqlDataSourceStatusEventArgs e)
    {
        for (int i = 0; i < e.Command.Parameters.Count; i++)
        {
            if (this.SqlDataSource1.SelectParameters[i].Direction == ParameterDirection.Output)
            {
                if (((ControlParameter)this.SqlDataSource1.SelectParameters[i]).ControlID != "Label_Ignore")
                {
                    ((TextBox)this.FindControl(((ControlParameter)this.SqlDataSource1.SelectParameters[i]).ControlID)).Text = e.Command.Parameters[i].Value.ToString();
                }
            }
        }
        
    }

    protected void Button_Save_Click(object sender, EventArgs e)
    {
        try
        {
            if (this.NianDu.Enabled)
            {
                if (this.SqlDataSource1.Insert() > 0)
                {
                    this.NianDu.Enabled = false;
                    this.YueFen.Enabled = false;
                    this.Notice = "保存成功";
                }
                else
                {
                    this.Notice = "保存失败";
                }
            }
            else
            {
                if (this.SqlDataSource1.Update() > 0)
                {
                    this.Notice = "保存成功";
                }
                else
                {
                    this.Notice = "保存失败";
                }
            }
        }
        catch (Exception se)
        {
            this.Notice = se.Message;
            this.Notice = "保存失败，请检查录入是否有误，计划是否重复。";
        }
    }
</script>
<html>
<head></head>
<body>
<script type="text/javascript" language="javascript" src="/common.js"></script>
<form id="form1" runat="server">

<asp:SqlDataSource ID="SqlDataSource1" runat="server" 
 ConnectionString="<%$ ConnectionStrings:SCMConnectionString1 %>" 
 SelectCommand="SELECT
@一分厂产品1=一分厂产品1
,@一分厂产品2=一分厂产品2
,@一分厂产品3=一分厂产品3
,@一分厂产品4=一分厂产品4
,@二分厂产品1=二分厂产品1
,@二分厂产品2=二分厂产品2
,@二分厂产品3=二分厂产品3
,@二分厂产品4=二分厂产品4
,@三分厂产品1=三分厂产品1
,@三分厂产品2=三分厂产品2
,@三分厂产品3=三分厂产品3
,@三分厂产品4=三分厂产品4
,@四分厂产品1=四分厂产品1
,@四分厂产品2=四分厂产品2
,@四分厂产品3=四分厂产品3
,@四分厂产品4=四分厂产品4
,@五分厂产品1=五分厂产品1
,@五分厂产品2=五分厂产品2
,@五分厂产品3=五分厂产品3
,@五分厂产品4=五分厂产品4
,@外购接箍1=外购接箍1
,@外购接箍2=外购接箍2
,@外购接箍3=外购接箍3
,@外购接箍4=外购接箍4
FROM 生产计划 where 年度=@年度 and 月份=@月份"
 InsertCommand="insert into 生产计划(
 年度
,月份
,一分厂产品1
,一分厂产品2
,一分厂产品3
,一分厂产品4
,二分厂产品1
,二分厂产品2
,二分厂产品3
,二分厂产品4
,三分厂产品1
,三分厂产品2
,三分厂产品3
,三分厂产品4
,四分厂产品1
,四分厂产品2
,四分厂产品3
,四分厂产品4
,五分厂产品1
,五分厂产品2
,五分厂产品3
,五分厂产品4
,外购接箍1
,外购接箍2
,外购接箍3
,外购接箍4)values(
@年度
,@月份
,@一分厂产品1
,@一分厂产品2
,@一分厂产品3
,@一分厂产品4
,@二分厂产品1
,@二分厂产品2
,@二分厂产品3
,@二分厂产品4
,@三分厂产品1
,@三分厂产品2
,@三分厂产品3
,@三分厂产品4
,@四分厂产品1
,@四分厂产品2
,@四分厂产品3
,@四分厂产品4
,@五分厂产品1
,@五分厂产品2
,@五分厂产品3
,@五分厂产品4
,@外购接箍1
,@外购接箍2
,@外购接箍3
,@外购接箍4);"
 UpdateCommand="update 生产计划 set
一分厂产品1=@一分厂产品1
,一分厂产品2=@一分厂产品2
,一分厂产品3=@一分厂产品3
,一分厂产品4=@一分厂产品4
,二分厂产品1=@二分厂产品1
,二分厂产品2=@二分厂产品2
,二分厂产品3=@二分厂产品3
,二分厂产品4=@二分厂产品4
,三分厂产品1=@三分厂产品1
,三分厂产品2=@三分厂产品2
,三分厂产品3=@三分厂产品3
,三分厂产品4=@三分厂产品4
,四分厂产品1=@四分厂产品1
,四分厂产品2=@四分厂产品2
,四分厂产品3=@四分厂产品3
,四分厂产品4=@四分厂产品4
,五分厂产品1=@五分厂产品1
,五分厂产品2=@五分厂产品2
,五分厂产品3=@五分厂产品3
,五分厂产品4=@五分厂产品4
,外购接箍1=@外购接箍1
,外购接箍2=@外购接箍2
,外购接箍3=@外购接箍3
,外购接箍4=@外购接箍4
where 年度=@年度 and 月份=@月份" onselected="SqlDataSource1_Selected"
>
<SelectParameters>
<asp:ControlParameter Name="年度" DbType="Int32" Size="4" ControlID="NianDu" />
<asp:ControlParameter Name="月份" DbType="Int32" Size="4" ControlID="YueFen" />
<asp:ControlParameter Name="一分厂产品1" DbType="Double" Size="8" Direction="Output" ControlID="Label_Ignore"  />
<asp:ControlParameter Name="一分厂产品2" DbType="Double" Size="8" Direction="Output" ControlID="CL12" />
<asp:ControlParameter Name="一分厂产品3" DbType="Double" Size="8" Direction="Output" ControlID="Label_Ignore" />
<asp:ControlParameter Name="一分厂产品4" DbType="Double" Size="8" Direction="Output" ControlID="CL14" />

<asp:ControlParameter Name="二分厂产品1" DbType="Double" Size="8" Direction="Output" ControlID="CL21" />
<asp:ControlParameter Name="二分厂产品2" DbType="Double" Size="8" Direction="Output" ControlID="CL22" />
<asp:ControlParameter Name="二分厂产品3" DbType="Double" Size="8" Direction="Output" ControlID="Label_Ignore" />
<asp:ControlParameter Name="二分厂产品4" DbType="Double" Size="8" Direction="Output" ControlID="Label_Ignore" />

<asp:ControlParameter Name="三分厂产品1" DbType="Double" Size="8" Direction="Output" ControlID="CL31" />
<asp:ControlParameter Name="三分厂产品2" DbType="Double" Size="8" Direction="Output" ControlID="CL32" />
<asp:ControlParameter Name="三分厂产品3" DbType="Double" Size="8" Direction="Output" ControlID="Label_Ignore" />
<asp:ControlParameter Name="三分厂产品4" DbType="Double" Size="8" Direction="Output" ControlID="Label_Ignore" />

<asp:ControlParameter Name="四分厂产品1" DbType="Double" Size="8" Direction="Output" ControlID="Label_Ignore" />
<asp:ControlParameter Name="四分厂产品2" DbType="Double" Size="8" Direction="Output" ControlID="CL42" />
<asp:ControlParameter Name="四分厂产品3" DbType="Double" Size="8" Direction="Output" ControlID="Label_Ignore" />
<asp:ControlParameter Name="四分厂产品4" DbType="Double" Size="8" Direction="Output" ControlID="Label_Ignore" />

<asp:ControlParameter Name="五分厂产品1" DbType="Double" Size="8" Direction="Output" ControlID="CL51" />
<asp:ControlParameter Name="五分厂产品2" DbType="Double" Size="8" Direction="Output" ControlID="Label_Ignore" />
<asp:ControlParameter Name="五分厂产品3" DbType="Double" Size="8" Direction="Output" ControlID="Label_Ignore" />
<asp:ControlParameter Name="五分厂产品4" DbType="Double" Size="8" Direction="Output" ControlID="Label_Ignore" />

<asp:ControlParameter Name="外购接箍1" DbType="Double" Size="8" Direction="Output" ControlID="CLW1" />
<asp:ControlParameter Name="外购接箍2" DbType="Double" Size="8" Direction="Output" ControlID="CLW2" />
<asp:ControlParameter Name="外购接箍3" DbType="Double" Size="8" Direction="Output" ControlID="Label_Ignore" />
<asp:ControlParameter Name="外购接箍4" DbType="Double" Size="8" Direction="Output" ControlID="Label_Ignore" />
</SelectParameters>
<InsertParameters>
<asp:ControlParameter Name="年度" DbType="Int32" Size="4" ControlID="NianDu" />
<asp:ControlParameter Name="月份" DbType="Int32" Size="4" ControlID="YueFen" />
<asp:ControlParameter Name="一分厂产品1" DbType="Double" Size="8" ControlID="Label_Ignore" />
<asp:ControlParameter Name="一分厂产品2" DbType="Double" Size="8" ControlID="CL12" />
<asp:ControlParameter Name="一分厂产品3" DbType="Double" Size="8" ControlID="Label_Ignore" />
<asp:ControlParameter Name="一分厂产品4" DbType="Double" Size="8" ControlID="CL14" />

<asp:ControlParameter Name="二分厂产品1" DbType="Double" Size="8" ControlID="CL21" />
<asp:ControlParameter Name="二分厂产品2" DbType="Double" Size="8" ControlID="CL22" />
<asp:ControlParameter Name="二分厂产品3" DbType="Double" Size="8" ControlID="Label_Ignore" />
<asp:ControlParameter Name="二分厂产品4" DbType="Double" Size="8" ControlID="Label_Ignore" />

<asp:ControlParameter Name="三分厂产品1" DbType="Double" Size="8" ControlID="CL31" />
<asp:ControlParameter Name="三分厂产品2" DbType="Double" Size="8" ControlID="CL32" />
<asp:ControlParameter Name="三分厂产品3" DbType="Double" Size="8" ControlID="Label_Ignore" />
<asp:ControlParameter Name="三分厂产品4" DbType="Double" Size="8" ControlID="Label_Ignore" />

<asp:ControlParameter Name="四分厂产品1" DbType="Double" Size="8" ControlID="Label_Ignore" />
<asp:ControlParameter Name="四分厂产品2" DbType="Double" Size="8" ControlID="CL42" />
<asp:ControlParameter Name="四分厂产品3" DbType="Double" Size="8" ControlID="Label_Ignore" />
<asp:ControlParameter Name="四分厂产品4" DbType="Double" Size="8" ControlID="Label_Ignore" />

<asp:ControlParameter Name="五分厂产品1" DbType="Double" Size="8" ControlID="CL51" />
<asp:ControlParameter Name="五分厂产品2" DbType="Double" Size="8" ControlID="Label_Ignore" />
<asp:ControlParameter Name="五分厂产品3" DbType="Double" Size="8" ControlID="Label_Ignore" />
<asp:ControlParameter Name="五分厂产品4" DbType="Double" Size="8" ControlID="Label_Ignore" />

<asp:ControlParameter Name="外购接箍1" DbType="Double" Size="8" ControlID="CLW1" />
<asp:ControlParameter Name="外购接箍2" DbType="Double" Size="8" ControlID="CLW2" />
<asp:ControlParameter Name="外购接箍3" DbType="Double" Size="8" ControlID="Label_Ignore" />
<asp:ControlParameter Name="外购接箍4" DbType="Double" Size="8" ControlID="Label_Ignore" />
</InsertParameters>
<UpdateParameters>
<asp:ControlParameter Name="年度" DbType="Int32" Size="4" ControlID="NianDu" />
<asp:ControlParameter Name="月份" DbType="Int32" Size="4" ControlID="YueFen" />
<asp:ControlParameter Name="一分厂产品1" DbType="Double" Size="8" ControlID="Label_Ignore" />
<asp:ControlParameter Name="一分厂产品2" DbType="Double" Size="8" ControlID="CL12" />
<asp:ControlParameter Name="一分厂产品3" DbType="Double" Size="8" ControlID="Label_Ignore" />
<asp:ControlParameter Name="一分厂产品4" DbType="Double" Size="8" ControlID="CL14" />

<asp:ControlParameter Name="二分厂产品1" DbType="Double" Size="8" ControlID="CL21" />
<asp:ControlParameter Name="二分厂产品2" DbType="Double" Size="8" ControlID="CL22" />
<asp:ControlParameter Name="二分厂产品3" DbType="Double" Size="8" ControlID="Label_Ignore" />
<asp:ControlParameter Name="二分厂产品4" DbType="Double" Size="8" ControlID="Label_Ignore" />

<asp:ControlParameter Name="三分厂产品1" DbType="Double" Size="8" ControlID="CL31" />
<asp:ControlParameter Name="三分厂产品2" DbType="Double" Size="8" ControlID="CL32" />
<asp:ControlParameter Name="三分厂产品3" DbType="Double" Size="8" ControlID="Label_Ignore" />
<asp:ControlParameter Name="三分厂产品4" DbType="Double" Size="8" ControlID="Label_Ignore" />

<asp:ControlParameter Name="四分厂产品1" DbType="Double" Size="8" ControlID="Label_Ignore" />
<asp:ControlParameter Name="四分厂产品2" DbType="Double" Size="8" ControlID="CL42" />
<asp:ControlParameter Name="四分厂产品3" DbType="Double" Size="8" ControlID="Label_Ignore" />
<asp:ControlParameter Name="四分厂产品4" DbType="Double" Size="8" ControlID="Label_Ignore" />

<asp:ControlParameter Name="五分厂产品1" DbType="Double" Size="8" ControlID="CL51" />
<asp:ControlParameter Name="五分厂产品2" DbType="Double" Size="8" ControlID="Label_Ignore" />
<asp:ControlParameter Name="五分厂产品3" DbType="Double" Size="8" ControlID="Label_Ignore" />
<asp:ControlParameter Name="五分厂产品4" DbType="Double" Size="8" ControlID="Label_Ignore" />

<asp:ControlParameter Name="外购接箍1" DbType="Double" Size="8" ControlID="CLW1" />
<asp:ControlParameter Name="外购接箍2" DbType="Double" Size="8" ControlID="CLW2" />
<asp:ControlParameter Name="外购接箍3" DbType="Double" Size="8" ControlID="Label_Ignore" />
<asp:ControlParameter Name="外购接箍4" DbType="Double" Size="8" ControlID="Label_Ignore" />
</UpdateParameters>
</asp:SqlDataSource>

<asp:Label ID="Label_Ignore" runat="server" Text="0" Visible="false"></asp:Label>

<div id="wintop" class="wintop">生产计划录入</div>
    <asp:Panel ID="Panel1" runat="server" CssClass="panel">
年 度：<asp:DropDownList ID="NianDu" runat="server" Width="80px" AutoPostBack="true">
    <asp:ListItem>2008</asp:ListItem>
    <asp:ListItem>2009</asp:ListItem>
    <asp:ListItem>2010</asp:ListItem>
    <asp:ListItem>2011</asp:ListItem>
    <asp:ListItem>2012</asp:ListItem>
    <asp:ListItem>2013</asp:ListItem>
    <asp:ListItem>2014</asp:ListItem>
    <asp:ListItem>2015</asp:ListItem>
    <asp:ListItem>2016</asp:ListItem>
    <asp:ListItem>2017</asp:ListItem>
    <asp:ListItem>2018</asp:ListItem>
    <asp:ListItem>2019</asp:ListItem>
    <asp:ListItem>2020</asp:ListItem>
</asp:DropDownList>

月 份：<asp:DropDownList ID="YueFen" runat="server" Width="80px" AutoPostBack="true">
    <asp:ListItem Value="0">年度</asp:ListItem>
    <asp:ListItem Value="1">1月份</asp:ListItem>
    <asp:ListItem Value="2">2月份</asp:ListItem>
    <asp:ListItem Value="3">3月份</asp:ListItem>
    <asp:ListItem Value="4">4月份</asp:ListItem>
    <asp:ListItem Value="5">5月份</asp:ListItem>
    <asp:ListItem Value="6">6月份</asp:ListItem>
    <asp:ListItem Value="7">7月份</asp:ListItem>
    <asp:ListItem Value="8">8月份</asp:ListItem>
    <asp:ListItem Value="9">9月份</asp:ListItem>
    <asp:ListItem Value="10">10月份</asp:ListItem>
    <asp:ListItem Value="11">11月份</asp:ListItem>
    <asp:ListItem Value="12">12月份</asp:ListItem>
</asp:DropDownList> 

        
        
        <asp:Button ID="Button_Save" runat="server" Text="保 存" CssClass="button" 
            UseSubmitBehavior="False" onclick="Button_Save_Click" />
             
        <input type="button" value="关 闭" class="button" onclick="parent.swin2_close();" />

    </asp:Panel>


<script>    putBillHead();</script>
    
<table border=1 style="border-collapse: collapse;text-align:center;" bordercolor=#000000>
<tr>
	<td height=60 colspan=7 style="font-size:26px;"><%=this.NianDu.SelectedItem.Text%>年<%=this.YueFen.SelectedItem.Text %>计划明细</td>
</tr>
<tr>
	<td width=100 height=30>分 厂</td>
	<td width=120>产 品</td>
	<td width=80>钢 级</td>
	<td width=140>规格(mm)</td>
	<td width=100>螺纹形式</td>
	<td width=80>单位</td>
	<td width=140>计划量</td>
</tr>
<tr>
	<td height=30 rowspan=2>一分厂</td>
	<td rowspan=2>套管管体</td>
	<td>J55</td>
	<td>φ139.7×7.72</td>
	<td>LC</td>
	<td>吨</td>
	<td><asp:TextBox ID="CL12" runat="server" CssClass="intxt1" Width="130"></asp:TextBox></td>
</tr>
<tr>
	<td>N80Q</td>
	<td>φ139.7×7.72</td>
	<td>LC</td>
	<td>吨</td>
	<td><asp:TextBox ID="CL14" runat="server" CssClass="intxt1" Width="130"></asp:TextBox></td>
</tr>
<tr>
	<td rowspan="2">二分厂</td>
	<td>油管管体</td>
	<td>J55</td>
	<td>φ73.1×5.51</td>
	<td>NU</td>
	<td>吨</td>
	<td><asp:TextBox ID="CL21" runat="server" CssClass="intxt1" Width="130"></asp:TextBox></td>
</tr>
<tr>
	<td height=30>套管管体</td>
	<td>J55</td>
	<td>φ139.7×7.72</td>
	<td>LC</td>
	<td>吨</td>
	<td><asp:TextBox ID="CL22" runat="server" CssClass="intxt1" Width="130"></asp:TextBox></td>
</tr>

<tr>
	<td rowspan="2">三分厂</td>
	<td>油管接箍</td>
	<td>J55</td>
	<td>φ88.9×12.5</td>
	<td>NU</td>
	<td>支</td>
	<td><asp:TextBox ID="CL31" runat="server" CssClass="intxt1" Width="130"></asp:TextBox></td>
</tr>

<tr>
	<td>套管接箍</td>
	<td>J55</td>
	<td>φ153.67×13.5</td>
	<td>LC</td>
	<td>支</td>
	<td><asp:TextBox ID="CL32" runat="server" CssClass="intxt1" Width="130"></asp:TextBox></td>
</tr>
<tr>
	<td>四分厂</td>
	<td height=30>套管保护器</td>
	<td>　</td>
	<td>5-1/2&quot;</td>
	<td>　</td>
	<td>套</td>
	<td><asp:TextBox ID="CL42" runat="server" CssClass="intxt1" Width="130"></asp:TextBox></td>
</tr>
<tr>
	<td>五分厂</td>
	<td>油管管体</td>
	<td>J55</td>
	<td>φ73.1×5.51</td>
	<td>NU</td>
	<td>吨</td>
	<td><asp:TextBox ID="CL51" runat="server" CssClass="intxt1" Width="130"></asp:TextBox></td>
</tr>
<tr>
	<td rowspan="2">外购接箍</td>
	<td>油管接箍</td>
	<td>J55</td>
	<td>φ88.9×12.5</td>
	<td>NU</td>
	<td>支</td>
	<td><asp:TextBox ID="CLW1" runat="server" CssClass="intxt1" Width="130"></asp:TextBox></td>
</tr>

<tr>
	<td>套管接箍</td>
	<td>J55</td>
	<td>φ153.67×13.5</td>
	<td>LC</td>
	<td>支</td>
	<td><asp:TextBox ID="CLW2" runat="server" CssClass="intxt1" Width="130"></asp:TextBox></td>
</tr>

</table>

    

<script>    putBillFoot();</script>

</form>
<script>
var notice = '<%=this.Notice %>';
if (notice != '') {
    parent.showmsgbox(notice);
}
</script>
<script>
    var textboxs = document.getElementsByTagName("input");
    var i;
    for (i = 0; i < textboxs.length; i++) {
        if (textboxs[i].className == "textbox" || textboxs[i].className == "intxt1" || textboxs[i].className == "intxt2") {
            textboxs[i].onfocus = function(e) { this.select(); };
        }
    }

    document.body.onkeypress = function(e) {
        if (!e) e = window.event;
        var tag = e.srcElement;
        if (!tag) tag = e.target;
        if (tag.className.toLowerCase() != "intxt1") return;
        var i;
        if (e.keyCode == 13) {
            for (i = 0; i < textboxs.length; i++) {
                if (tag == textboxs[i]) {
                    if (i < textboxs.length - 1) {
                        textboxs[i + 1].focus();
                        return false;
                    }
                }
            }
        }
    };

</script>

</form>
</body>
</html>